package com.indicator.cMetric;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import com.util.set.impl.BasicExSet;
import com.util.set.inter.ExSetInter;
import com.util.solution.impl.QAPSolution;
import com.util.solution.inter.Solution;

public class cMetric {
	private int objNum = 2;
	private List<Solution> subSetA = new ArrayList<Solution>();
	private List<Solution> subSetB = new ArrayList<Solution>();
	
	ExSetInter<Solution> matrix1 = new BasicExSet<Solution>();
	ExSetInter<Solution> matrix2 = new BasicExSet<Solution>();
	
	public static void main(String [] args){
		new cMetric().execute();
	}
	
	public void execute(){
//		String path1 = "E:/论文实验/QAP/cdg_adp/60-2/-0.8/adp_60_2_%d.txt";
//		String path2 = "files/results/qap/pls/60-2/-0.8/60-2-%d.txt";
		
//		String path1 = "E:/论文实验/DIMA/new_results/28-7/%d_cdg.txt";
//		String path2 = "E:/论文实验/DIMA/pls/28-7/%d-pls.txt";
		String path1 = "E:/论文实验/TSP/new_cdg/ClusterAB300/adp_ClusterAB300_%d.txt";
		String path2 = "files/results/tsp/pls/ClusterAB300/adp_ClusterAB300_%d.txt";
		for(int i=0;i<2;i++){
			String fullPath = String.format(path1, i);
			try {
				BufferedReader wb = new BufferedReader(new InputStreamReader(
				        new FileInputStream(fullPath)));
				for (String line = wb.readLine(); line != null; line = wb.readLine()) {	 
					Solution s = new QAPSolution(60, this.objNum, -1);
					String [] str = line.split("\\s+");
					for(int k=0;k<objNum;k++){
						s.object_val[k] = Integer.parseInt(str[k]);
					}
					matrix1.add(s);
				}
				wb.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		for(int i=0;i<2;i++){
			String fullPath = String.format(path2, i);
			try {
				BufferedReader wb = new BufferedReader(new InputStreamReader(
				        new FileInputStream(fullPath)));
				for (String line = wb.readLine(); line != null; line = wb.readLine()) {	 
					Solution s = new QAPSolution(60, this.objNum, -1);
					String [] str = line.split("\\s+");
					for(int k=0;k<objNum;k++){
						s.object_val[k] = Integer.parseInt(str[k]);
					}
					matrix2.add(s);
				}
				wb.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		for(Solution B : matrix2.getSolutions()){
			for(Solution A : matrix1.getSolutions()){
				if(A.compareTo(B)>0){
					subSetB.add(B);
					break;
				}
			}
		}
		for(Solution A : matrix1.getSolutions()){
			for(Solution B : matrix2.getSolutions()){
				if(B.compareTo(A)>0){
					subSetA.add(A);
					break;
				}
			}
		}
		System.out.println("C(A,B) = "+(float)(subSetB.size()*1.0/matrix2.getPopSize()));
		System.out.println("C(B,A) = "+(float)(subSetA.size()*1.0/matrix1.getPopSize()));
	}
}